package com.zs.games.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zs.games.resultTool.CimResponse;
import com.zs.games.entity.GameNews;
import com.zs.games.param.PageQuery;
import com.zs.games.param.IdParam;
import com.zs.games.param.UserCommentNewParam;
import com.zs.games.service.GameNewsService;
import com.zs.games.vo.GameNewVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/news")
@Api(tags = "新闻管理")
public class GameNewsController {

    @Autowired
    private GameNewsService gameNewsService;

    @GetMapping("/pageList")
    @ApiOperation("分页获取新闻列表")
    @ApiOperationSupport(order = 1)
    public CimResponse<IPage<GameNewVo>> pageList(PageQuery param) {
        return CimResponse.okData(gameNewsService.getPageNews(param));
    }

    @GetMapping("/getInfo")
    @ApiOperation("根据ID获取新闻详情")
    @ApiOperationSupport(order = 2)
    public CimResponse<GameNewVo> getGameNewsById(@Validated IdParam param) {
        return CimResponse.okData(gameNewsService.getGameNewsById(param.getId()));
    }

    @PostMapping("/addNews")
    @ApiOperation("创建新闻")
    @ApiOperationSupport(order = 3)
    public CimResponse<Boolean> createGameNews(@RequestBody GameNews gameNews) {
        return CimResponse.okData(gameNewsService.createGameNews(gameNews));
    }

    @PostMapping("/updateNews")
    @ApiOperation("更新新闻")
    @ApiOperationSupport(order = 4)
    public CimResponse<Boolean> updateGameNews( @RequestBody GameNews gameNews) {
        return CimResponse.okData(gameNewsService.updateGameNews(gameNews));
    }

    @PostMapping("/delete")
    @ApiOperation("删除新闻")
    @ApiOperationSupport(order = 5)
    public CimResponse<Boolean> deleteGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(gameNewsService.deleteGameNews(param.getId()));
    }
    @PostMapping("/addPraise")
    @ApiOperation("点赞新闻")
    @ApiOperationSupport(order = 6)
    public CimResponse<Boolean> addPraiseGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(gameNewsService.praiseGameNews(param.getId()));
    }
    @PostMapping("/cancelPraiseGameNews")
    @ApiOperation("取消点赞新闻")
    @ApiOperationSupport(order = 7)
    public CimResponse<Boolean> cancelPraiseGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(gameNewsService.cancelPraiseGameNews(param.getId()));
    }
    @PostMapping("/collect")
    @ApiOperation("收藏新闻")
    @ApiOperationSupport(order = 8)
    public CimResponse<Boolean> collect(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(gameNewsService.collectGameNews(param.getId()));
    }
    @PostMapping("/cancelCollect")
    @ApiOperation("取消收藏新闻")
    @ApiOperationSupport(order = 9)
    public CimResponse<Boolean> cancelCollect(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(gameNewsService.cancelCollectGameNews(param.getId()));
    }
    @PostMapping("/addComment")
    @ApiOperation("评论新闻")
    @ApiOperationSupport(order = 10)
    public CimResponse<Boolean> addComment(@RequestBody @Validated UserCommentNewParam param) {
        return CimResponse.okData(gameNewsService.commentGameNews(param));
    }
    @PostMapping("/deleteComment")
    @ApiOperation("删除评论")
    @ApiOperationSupport(order = 11)
    public CimResponse<Boolean> deleteComment(@RequestBody @Validated UserCommentNewParam param) {
        return CimResponse.okData(gameNewsService.deleteCommentGameNews(param.getCommentId()));
    }

    // 其他接口同理
}
